
import { _decorator, Component, Node, EditBoxComponent, director} from 'cc';
import { SceneFlag } from './SceneFlag';
import { getNet } from './Other/Util';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = LobbyRoomDirector
 * DateTime = Mon Feb 07 2022 16:47:01 GMT+0800 (中国标准时间)
 * Author = awi1299
 * FileBasename = LobbyRoomDirector.ts
 * FileBasenameNoExtension = LobbyRoomDirector
 * URL = db://assets/script/LobbyRoomDirector.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('LobbyRoomDirector')
export class LobbyRoomDirector extends Component {
    @property(EditBoxComponent)
    editBox:EditBoxComponent = null

    @property(Node)
    buttonReconnect:Node

    start () {
        const net = getNet()
        net.curScene = SceneFlag.LOBBY
        console.log(net.curScene)
    }

    async enterRoom(){
        const net = getNet()
        net.joinRoomId = this.editBox.string
        director.loadScene(SceneFlag.GAME)
    }

    reconnect(){
        const net = getNet()
        net.isReconnect = true
        director.loadScene(SceneFlag.GAME)
    }

    update(){
        const net = getNet()
        if (!net.canReconnect) {
            this.buttonReconnect.active = false
        }
    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
